class Solution {
    public int longestPalindrome(String s) {
        char[] cc = new char[122 - 65 + 1];
        char[] ss = s.toCharArray();
        for (char c : ss) {
            cc[c - 'A']++;
        }

        int total = 0;
        boolean hasSingle = false;
        for (char c : cc) {
            if (c % 2 == 1) hasSingle = true;
            total += c / 2;
        }
        total *= 2;
        if (hasSingle) total += 1;
        return total;
    }
}
